from typing import List


class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class TreePath:
    def __init__(self):
        self.path = []
        self.res = []

    def allPath(self, root: TreeNode) -> List[List[int]]:
        self.dfs(root)
        return self.res

    def dfs(self, node: TreeNode):
        if not node:
            return

        self.path.append(node.val)

        if not node.left and not node.right:
            self.res.append(list(self.path))

        self.dfs(node.left)
        self.dfs(node.right)

        self.path.pop()